package com.ppp.poi.bean.enumeration;


import com.ppp.poi.common.AppConstant;

/**
 * RES_STATUS
 */
public enum RES_STATUS {
  FAILED(-1, "未知错误"),
  SUCCESS(0, "SUCCESS"),
  SERVER_UNKONW_ERROR(500, "服务器开小差了,请稍后再试"),
  MISS_PARAM(400, "参数异常"),
  DB_ERROR(10000, "DB操作失败"),
  SESSION_OVERTIME(302, "会话已过期，请重新登录。"),
  SESSION_INIT_ERROR(303, "建立会话异常"),
  STRATEGY_CHECK_ERROR(30001, "检测失败"),
  RESOURCE_NOT_EXIST(50001, "资源不存在"),
  ;

  public final int code;
  public final String msg;

  RES_STATUS(int code, String msg) {
    this.code = code;
    this.msg = msg;
  }

  public static RES_STATUS findStatusByCode(int code) {
    for (RES_STATUS status : RES_STATUS.values()) {
      if (status.code == code) {
        return status;
      }
    }
    return null;
  }


  /**
   * success:Y not success:N
   */
  public static String isSuccess(int code) {
    if (code == RES_STATUS.SUCCESS.code) {
      return AppConstant.METHOD_SUCCESS;
    } else {
      return AppConstant.METHOD_FAIL;
    }
  }
}
